/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NouveauFilm.java
 *
 * Created on 21 janv. 2011, 14:30:00
 */
/**
 *
 * finalisation la fiche ajout film le 28 janv 2011
 */

package org.cinema.view.admin;

import com.itextpdf.text.SplitCharacter;
import java.awt.Color;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Date;
import java.sql.Time;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.cinema.dao.film.FilmsDao;
import org.cinema.dao.film.FilmsInfo;
import org.cinema.dao.salle.SallesDao;
import org.cinema.dao.salle.SallesInfo;
import org.cinema.dao.seance.SeancesDao;
import org.cinema.dao.seance.SeancesInfo;
import org.cinema.utils.Log;

/**
 *
 * @author lynda
 */
public class NouveauFilm extends javax.swing.JPanel {

 /* recuperer l'objet film*/
    FilmsInfo film;
    FilmsDao filmDao;
    List<FilmsInfo> filmsList;
 /* recuperer l'objet salle */
    List<SallesInfo> sallesList;
    SallesDao salleDao;
    SallesInfo salle;
  /*   recuperer l'objet séance*/
    SeancesDao seanceDao;
    SeancesInfo seance;
    List<SeancesInfo> seanceList;
    ArrayList<SeancesInfo> mesSeances;



    /** Creates new form NouveauFilm */
    public NouveauFilm() {
        initComponents();
        /* initialiser film*/
        filmDao = new FilmsDao();
        film = new FilmsInfo(null, null, null, null, null, 0, null);
        filmsList = filmDao.allFilm();
        remplirFilm();


        /* initialiser salle*/
        salleDao= new SallesDao();
        salle= new SallesInfo(null, 0, false);

        /*  initialiser seance*/
        seance = new SeancesInfo(-1, -1, null, null,false);
        seanceDao = new SeancesDao();
        seanceList = seanceDao.allSeance();

        // récupérer la liste de toutes les salles
        sallesList= salleDao.allSalle();
        RemplirSalleListe();

        /* les deux champs
         qui récupère l'id de la salle choisi ainsi que l'id du nouveau film
         sont invisible, ils sont utilisés  pour référencer la salle et le film */
         this.jTextField10.setVisible(false);
         this.jTextField14.setVisible(false);



       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jTextField11 = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jTextField12 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel18 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jLabel19 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jTextField10 = new javax.swing.JTextField();
        jTextField13 = new javax.swing.JTextField();
        jTextField14 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();

        jTabbedPane1.setPreferredSize(new java.awt.Dimension(900, 900));

        jLabel1.setText("Titre  :  ");

        jLabel2.setText("Durée:");

        jLabel3.setText("Date de Sortie:");

        jLabel4.setText("Acteurs:");

        jLabel5.setText("Résumé:");

        jLabel6.setText("Popularité:");

        jButton1.setText("Parcourir l'image");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Ajouter ");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Rafraichir ");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel10.setForeground(new java.awt.Color(255, 0, 0));

        jLabel9.setBackground(new java.awt.Color(0, 204, 255));
        jLabel9.setText("Etape 1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(269, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addGap(29, 29, 29)
                                .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6))
                                .addGap(45, 45, 45)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                                    .addComponent(jTextField3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(156, 156, 156)
                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addGap(206, 206, 206))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(548, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addGap(184, 184, 184))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel5))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6)))
                .addGap(81, 81, 81)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE))
                .addGap(30, 30, 30)
                .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Nouveau Film  ", jPanel1);

        jLabel13.setText("Debut de projection:");

        jLabel14.setText("Heure de projection:");

        jLabel15.setText("(Exemple date : 2010-12-12)");

        jLabel17.setText("Consulter la liste des scéances organisées selon la salle choisie:");

        jList1.setToolTipText("");
        jScrollPane1.setViewportView(jList1);

        jLabel18.setText("(Exemple heure 09:30)");

        jButton5.setText("Ajouter");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jRadioButton1.setText("3D");

        jRadioButton2.setText("2D\n");

        jLabel19.setText("Avec :\n");

        jLabel11.setText("Le nouveau Film:");

        jLabel12.setText("La liste des salles:");

        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });

        jLabel7.setText("Nombre de places:");

        jLabel8.setText("Equipement 3D:");

        jLabel20.setBackground(new java.awt.Color(51, 153, 255));
        jLabel20.setText("Etape 2");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "[choisir un film]" }));
        jComboBox1.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBox1PopupMenuWillBecomeVisible(evt);
            }
        });
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel21.setText("La liste des films :");

        jButton4.setText("Actualiser");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(19, 19, 19)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel13)
                                    .addComponent(jLabel14))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jTextField11)
                                            .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jTextField14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(jTextField12, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
                                        .addGap(18, 18, 18))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(52, 52, 52))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                            .addComponent(jLabel19)
                                            .addGap(35, 35, 35)
                                            .addComponent(jRadioButton1)
                                            .addGap(39, 39, 39))))
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(108, 108, 108)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addGap(71, 71, 71)
                                                .addComponent(jRadioButton2))
                                            .addComponent(jButton5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel18))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel15)))
                                .addGap(28, 28, 28))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel21))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jTextField13)
                                            .addComponent(jComboBox1, 0, 181, Short.MAX_VALUE))
                                        .addGap(52, 52, 52)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel8)
                                            .addComponent(jLabel12)
                                            .addComponent(jLabel7))
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel16, javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                    .addComponent(jTextField8, javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jTextField9, javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jComboBox3, javax.swing.GroupLayout.Alignment.LEADING, 0, 161, Short.MAX_VALUE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 172, Short.MAX_VALUE))))
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)))))
                        .addGap(0, 0, 0))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addGap(116, 116, 116))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel20)
                .addGap(13, 13, 13)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1)
                    .addComponent(jLabel21)
                    .addComponent(jLabel12)
                    .addComponent(jComboBox3))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                            .addComponent(jLabel11)
                            .addComponent(jTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jTextField9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jTextField8))))
                .addGap(5, 5, 5)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(147, 147, 147)
                        .addComponent(jLabel16))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                        .addGap(4, 4, 4)))
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addComponent(jLabel19))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButton2)
                            .addComponent(jRadioButton1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(74, 74, 74))
        );

        jTabbedPane1.addTab("Nouvelle Séance   ", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      /* lire l'image avec BufferedInputStream */
        BufferedInputStream r = null;
     /* parcourir l'image avec JFileChooser*/
       JFileChooser chooser = new JFileChooser();
        chooser.setVisible(true);
    /* ajouter un filtre qui permet de lire les fichiers images exemple
     jpg, png et gif*/
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
        "JPG & GIF Images", "jpg", "gif");
    chooser.setFileFilter(filter);
    int returnVal = chooser.showOpenDialog(chooser);
    if(returnVal == JFileChooser.APPROVE_OPTION) {
       System.out.println("You chose to open this file: " +
            chooser.getSelectedFile().getName());
       /* recuperer le nom de l'image séléctionnée et qui sera enregistrer
        dans la base de données*/
        jTextField7.setText(chooser.getSelectedFile().getName());

    }
       String fichier =  chooser.getSelectedFile().getName();
      String path = chooser.getSelectedFile().getAbsolutePath();

      
     

        
  /* ajouter l'image dans tools/images */
    if (fichier!=null){
            try {
                r = new BufferedInputStream(new FileInputStream(path));
                FileOutputStream w = new FileOutputStream("tools/images/" + fichier);
                int val = 0;
                while ((val = r.read()) != -1) {
                    w.write(val);
                }
            } catch (IOException ex) {
                Logger.getLogger(NouveauFilm.class.getName()).log(Level.SEVERE, null, ex);

        }

    }//GEN-LAST:event_jButton1ActionPerformed
    }    
    // cliquer pour ajouter un nouveau film qui n'existe pas dans la base
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
     /* initialiser film */
       film = new FilmsInfo(null, null, null, null, null, 0, null);
       filmDao = new FilmsDao();
       /* les champs ne doivent pas être vide*/
        verifier();
       /* ajouterFilm() permt d'ajouter un film dans la base de données */
         ajouterFilm ();
           /* recuperer le nouveau film */
       this.jTextField10.setText(new Integer(film.getId()).toString());
       film = filmDao.getFilm(film.getId());
       String nom = film.getTitre();
       this.jTextField13.setText(nom);
           

       
             
     
    }//GEN-LAST:event_jButton2ActionPerformed
  private void verifier(){
        if ( jTextField1.getText().equals("") || jTextField12.getText().equals("")
                || jTextField3.getText().equals("") || jTextField4.getText()
                .equals("") || jTextField5.getText().equals("") &&
                jTextField6.getText().equals("") || jTextField7.getText()
               .equals("")){
           jLabel10.setText("les champs ne doivent pas être vides");
          JOptionPane.showMessageDialog(null, "le film n'est pas ajouter");

       }
  }




    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        /* rafraichir les champs en cas d'erreur*/
        clear();
    }//GEN-LAST:event_jButton3ActionPerformed
    /* Ajouter une nouvelle séance */
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        verifierDateSeance();
        AjouterSeance();
        Refresh();
    }//GEN-LAST:event_jButton5ActionPerformed
    private void verifierDateSeance(){
        String temps[];
          String debut = jTextField11.getText();
            temps = debut.split("-");
            seance.setDebut(new Date(Integer.parseInt(temps[0]),
                    Integer.parseInt(temps[1]),
                    Integer.parseInt(temps[2])));

     /* verifier que la date de la nouvelle séance est > à la date actuelle*/
           Date sDate = new Date(System.currentTimeMillis());
           String Actuel=sDate.toString();
            String number[] = Actuel.split("-");
            int annee = Integer.parseInt(number[0]);
            int mois = Integer.parseInt(number[1]);
            int jour = Integer.parseInt(number[2]);
    /*détérminer la validité de la date saisie*/
            int year =Integer.parseInt(temps[0]);
            int month = Integer.parseInt(temps[1]);
            int day = Integer.parseInt(temps[2]);
            if (annee <= year && month <= mois && day <= jour ){
             JOptionPane.showMessageDialog(null, "la date doit être supérieur à la date courante" );

            }
    }




    /*  Selectionner une salle qui va générer automatiquement son nombre de
   place et son equipement 3D*/
    private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
      if (jComboBox3.getSelectedItem() != null)
         {
        int id = Integer.parseInt(((String) jComboBox3.getSelectedItem()).split(" ")[0]);
        this.jTextField14.setText(new Integer(id).toString());
        salle = salleDao.getSalle(id);
        this.jTextField8.setText(new Integer(salle.getNbPlace()).toString());
        this.jTextField9.setText(String.valueOf(salle.isEstTroisD()));
        /*  afficher la liste des séances selon la salle séléctionnée*/
       // seance= seanceDao.getSeance(id);

       mesSeances=new ArrayList<SeancesInfo>()  ;
        for (SeancesInfo si: seanceList){
            if (si.getSalleid()== id){
                mesSeances.add(si);
               
              }
        }

        String nomSalle = salleDao.getSalle(id).getNom();
        /* Jlist  */
          DefaultListModel df = new DefaultListModel();
        for (SeancesInfo s:mesSeances){
            film= filmDao.getFilm(s.getFilmid());
            String titre = film.getTitre();
            Time duree = film.getDuree();

            Date Dateproject = s.getDebut();
            /* l'heure de debut de la séance*/
            Time heure = s.getHeure();
            
            String debut=heure.toString();
            String number[] = debut.split(":");

            int dh = Integer.parseInt(number[0]);
            int dm = Integer.parseInt(number[1]);

             /* la durée du film*/
      

        String laduree= duree.toString();
        String nombre [];
        nombre = laduree.split(":");

         int h=Integer.parseInt(nombre[0]);
         int m= Integer.parseInt(nombre[1]);

         /* la date de fin du film est le debut de séance + la durée du film */
         int entretien = 15;
         int hour = dh+h;
         int minute = dm+m+entretien;

            while (minute-60>0){

                hour= hour+1;
                minute= minute-60;
                if (hour>23 && minute>59){
                    JOptionPane.showMessageDialog(null, "erreur, l'heure de"
                            + " projection ne doit pas être > à 00:00");
                }
            }

          String fin;
          fin = hour+":"+minute;
          


           
            /* ajoute */
          
           
            String ligne = "  " + nomSalle + "  " + titre + "  "+duree + "  "+
            Dateproject+"  "+heure+" "+fin;
            df.addElement(ligne);
             }
            
            jList1.setModel(df);
        
        
        }
    }//GEN-LAST:event_jComboBox3ActionPerformed
   /* actualiser les champs*/
      private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        this.jTextField8.setText("");

        this.jTextField9.setText("");

        this.jTextField10.setText("");

        this.jTextField11.setText("");
         this.jTextField13.setText("");
        
        this.jTextField14.setText("");



      }//GEN-LAST:event_jButton4ActionPerformed
  /* la liste de film*/
      private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
         
          if (jComboBox1.getSelectedItem() != null)
         {
        int id = Integer.parseInt(((String) jComboBox1.getSelectedItem()).split(" ")[0]);
        film = filmDao.getFilm(id);
        System.out.println("c'est l'id n°"+ film.getId());
       System.out.println("le titre"+ film.getTitre());

         this.jTextField13.setText("");
         this.jTextField13.setText(film.getTitre());
         this.jTextField10.setText(new Integer(film.getId()).toString());
          }
      }//GEN-LAST:event_jComboBox1ActionPerformed

      private void jComboBox1PopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBox1PopupMenuWillBecomeVisible
         remplirFilm();
      }//GEN-LAST:event_jComboBox1PopupMenuWillBecomeVisible
 private void remplirFilm(){
     
       filmsList = filmDao.allFilm();
       jComboBox1.removeAllItems();
        for (FilmsInfo fi : filmsList) {
            Log.log(fi.getTitre());
            this.jComboBox1.addItem("" + fi.getId() + " " + fi.getTitre());
           this.jTextField13.setText(film.getTitre());
           this.jTextField10.setText(new Integer(film.getId()).toString());
        }
     
     
 }

    private void ajouterFilm() {
                  

            film.setTitre(jTextField1.getText());
              

            // convertir le type String to Time
            String dure;
            String[] nombre;

            dure = jTextField2.getText();
            
            nombre = dure.split(":");
            film.setDuree(new Time(
                    Integer.parseInt(nombre[0]),
                    Integer.parseInt(nombre[1]), 0));
    
             String date = jTextField3.getText();
               
             Date madate = Date.valueOf(date);
             System.out.println("hg"+ madate.getMonth());
 



            film.setDateSortie(madate);
           System.out.println(film.getDateSortie());

            film.setActeur(jTextField4.getText());
            film.setResume(jTextField5.getText());
               System.out.println(jTextField5.getText());

            String popular = jTextField6.getText();
               System.out.println(jTextField6.getText());
            // convertir le string en float
            film.setPopularite(Float.valueOf(popular.trim()).floatValue());
            film.setImage(jTextField7.getText());
               System.out.println(jTextField7.getText());

            if (filmDao.saveFilm(film))
            {
              
                JOptionPane.showMessageDialog(null,
                    "film est bien enregistré dans la base.");
               

            } else {
                JOptionPane.showMessageDialog(null, "désolé le film n'est pas enregistré");
            }

       // }



    }




 private void clear() {
        // le titre vide
        this.jTextField1.setText("");
        // reset durée
        this.jTextField2.setText("");
        // reset date de sortie
        this.jTextField3.setText("");
        // reset acteurs
        this.jTextField4.setText("");
        // reset resume
        this.jTextField5.setText("");
        // reset popularite
        this.jTextField6.setText("");
        // changer l'image
        this.jTextField7.setText("");


    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField13;
    private javax.swing.JTextField jTextField14;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    // End of variables declaration//GEN-END:variables

    private void RemplirSalleListe() {
        sallesList=salleDao.allSalle();
                
        jComboBox3.removeAllItems();
        for(SallesInfo si:sallesList){
         this.jComboBox3.addItem("" + si.getId() + " " + si.getNom());
        }
    }

   

    /* methode qui permet d'ajouter une séance pr un film donnée*/
    private void AjouterSeance() {
         /* ajouter l'id du nouveau film */
          seance.setFilmid(Integer.parseInt(jTextField10.getText()));
          seance.setSalleid(Integer.parseInt(jTextField14.getText()));
          /* ajouter l'id de la salle choisie*/
//          seance.setSalleid(Integer.parseInt(jTextField10.getText()));
          /* debut de la nouvelle séance*/
            String[] temps;
        /* convertir le type String to Date java.sql */
            String debut = jTextField11.getText();
            temps = debut.split("-");
            seance.setDebut(new Date(Integer.parseInt(temps[0]),
                    Integer.parseInt(temps[1]),
                    Integer.parseInt(temps[2])));

 

       /* l'heure de projection */
       /* convertir le type String to Time java.sql */

            String heure = jTextField12.getText();
            temps = heure.split(":");
            seance.setHeure(new Time(Integer.parseInt(temps[0]),
                    Integer.parseInt(temps[1]), 0));

         /* si on séléctionne le radio boutton 3D alors on mets estTroisD
          à true, et lorsqu'on séléctionne 2D alors estTroisD est false.
          */
            if (jRadioButton1.isSelected()){
                seance.setEstTroisD(true);
                System.out.println(jRadioButton1.isSelected());
            } else if (jRadioButton2.isSelected()){
                seance.setEstTroisD(false);
                }
              if (seanceDao.saveSeance(seance))
            {
               // refresh();
                JOptionPane.showMessageDialog(null,
                    "La nouvelle séance est bien enregistré.");
                 this.jButton2.setEnabled(false);

            } else {
                JOptionPane.showMessageDialog(null, "désolé la séance n'est pas enregistré");
            }



    






    }

    private void Refresh() {

      sallesList =  salleDao.allSalle();
       jComboBox3.removeAllItems();
       jList1.removeAll();
       for (SallesInfo si: sallesList){
           this.jComboBox3.addItem(""+si.getId()+" "+si.getNom());
       }
       
           
      

       
    }




   

}
